package com.tecklab.demo.handler;

import cn.dev33.satoken.exception.SaTokenException;
import com.tecklab.demo.common.BizException;
import com.tecklab.demo.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Deacription TODO
 * @Author sunking
 * @Date 2022/12/7} 下午4:37
 **/
@ControllerAdvice
@Slf4j
public class GlobalControllerExHanlder {
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result handleHttpException(Exception ex){
        log.error("接口异常", ex);
        return Result.error("接口异常");
    }

    @ExceptionHandler(value = BizException.class)
    @ResponseBody
    public Result handleBizException(BizException exception){
        return Result.error(exception.getMessage());
    }



    @ExceptionHandler(value = SaTokenException.class)
    @ResponseBody
    public Result handleException(SaTokenException ex){
        log.error("接口异常", ex);
        return Result.error(501, "会话失效，请重新登录");
    }
}
